home *** CD-ROM | disk | FTP | other *** search
/ Nejlepší hry / Nejlepsi hry.iso / hry / sea of chaos / sea_install.msi / _15C39AAA7726369D39812BD40F01CF6A / _DF008A9F9A174637B356D995A1B1FA60 < prev    next >
Text File  |  2005-08-25  |  1KB  |  59 lines

  1. //like the impact shader, but makes tex coords based on direction of view for use in env map lookup
  2.  
  3. //iew,projection transform
  4. float4x4 matViewProj;
  5.  
  6. //camera position in world space
  7. float4 cameraPos;
  8.  
  9. //size modifier of particle
  10. float size;
  11.  
  12. //direction of up and of right
  13. float3 dirUp;
  14. float3 dirRight;
  15.  
  16. //shader input
  17. struct VS_INPUT
  18. {
  19.     float4 Pos : POSITION;
  20.     float3 Tex : TEXCOORD0;
  21. };
  22.  
  23. //shader output
  24. struct VS_OUTPUT
  25. {
  26.     float4 Pos : POSITION;
  27.     float2 Tex : TEXCOORD0;
  28.     float3 Env : TEXCOORD1;
  29. };
  30.  
  31. //shader code
  32. VS_OUTPUT VShader(VS_INPUT In)
  33. {
  34.     VS_OUTPUT Out;
  35.     
  36.     //calc tex coords centered around 0,0 and copy normal coord though
  37.     float2 tc=In.Tex.xy-0.5f;
  38.     Out.Tex=In.Tex;
  39.     
  40.     //transform pos
  41.     Out.Pos=mul(matViewProj,In.Pos);
  42.     
  43.     //rotate and expand outwards from center point, based on distance and tex coord
  44.     float2x2 matRot={cos(In.Tex.z),sin(In.Tex.z),-sin(In.Tex.z),cos(In.Tex.z)};
  45.     float2 posOffset=mul(matRot,tc);
  46.     
  47.     float dist=distance(cameraPos,In.Pos);
  48.     Out.Pos.xy+=(1.0f/sqrt(dist))*posOffset*size;
  49.     
  50.     //calc env map vector that is the view direction (with corners outwards from tex coord)
  51.     float3 dir=normalize(In.Pos.xyz-cameraPos);
  52.     dir+=posOffset.y*dirRight;
  53.     dir+=posOffset.x*dirUp;    
  54.     Out.Env=dir;
  55.  
  56.     //spit out the results
  57.     return Out;
  58. }
  59.